package cn.kgc.vue.controller;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.entity.Dept;
import cn.kgc.vue.response.ResponseResult;
import cn.kgc.vue.service.DeptService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/9/24
 * @description
 */
@RestController
@RequestMapping("dept")
public class DeptController {

    @Resource
    private DeptService deptService;

    // 部门列表
    @GetMapping("list")
    public ResponseResult deptList() {

        List<Dept> list = deptService.list();

        return ResponseResult.success()
                .data("deptList", list);
    }

    // 部分分页
    @PostMapping("page")
    public ResponseResult deptPage(@RequestBody QueryCondition<Dept> queryCondition) {

       return deptService.deptPage(queryCondition);
    }

    // 添加或修改
    @PostMapping("addOrUpdate")
    public ResponseResult addOrUpdateDept(@RequestBody Dept dept) {

      return   deptService.saveOrUpdate(dept) ? ResponseResult.success() : ResponseResult.fail();
    }


    // 删除部门信息
    @DeleteMapping("delete/{id}")
    public ResponseResult deleteDept(@PathVariable("id") Integer id) {

        return   deptService.delteDept(id);
    }
}
